package com.vm.adapter;

import java.util.List;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.vm.commons.VMConst;
import com.vm.model.Scene;
import com.vm.utils.MyDisplayImageOptions;
import com.wwtscapp.apk.R;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

@SuppressLint({ "HandlerLeak", "InflateParams" })
@SuppressWarnings("deprecation")
public class SoftImageAdapter extends BaseAdapter {
	@SuppressWarnings("unused")
	private List<String> imageUrls; // 图片地址list
	private Context context;
	private SoftImageAdapter self;
	Uri uri;
	Intent intent;
	ImageView imageView;
	public static List<Scene> scenes;
	// public static Integer[] imgs = {
	// R.drawable.one,
	// R.drawable.two,
	// R.drawable.three,
	// R.drawable.four
	// };

	@SuppressWarnings("static-access")
	public SoftImageAdapter(Context context, List<Scene> scenes) {
		// this.imageUrls = imageUrls;
		this.context = context;
		this.self = this;
		this.scenes = scenes;
	}

	public int getCount() {
		return Integer.MAX_VALUE;
	}

	public Object getItem(int position) {
		return scenes.get(position%scenes.size());
	}

	public long getItemId(int position) {
		return position;
	}

	@SuppressWarnings("unused")
	private Handler mHandler = new Handler() {
		public void handleMessage(Message msg) {
			try {
				switch (msg.what) {
				case 0: {
					self.notifyDataSetChanged();
				}
					break;
				}

				super.handleMessage(msg);
			} catch (Exception e) {
			}
		}
	};

	public View getView(int position, View convertView, ViewGroup parent) {

		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(
					R.layout.soft_image_item, null); // 实例化convertView
			Gallery.LayoutParams params = new Gallery.LayoutParams(
					Gallery.LayoutParams.WRAP_CONTENT,
					Gallery.LayoutParams.WRAP_CONTENT);
			convertView.setLayoutParams(params);
			convertView.setTag(scenes);

		} else {

		}
		Scene scene=scenes.get(position%scenes.size());
		imageView = (ImageView) convertView.findViewById(R.id.gallery_image);
		Bitmap bitmap = ImageLoader.getInstance().loadImageSync(
				VMConst.URL + scene.getImageUrl(),
				MyDisplayImageOptions.getInstance());
		imageView.setImageBitmap(bitmap);
		return convertView;

	}

}
